home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / MSG Demo 1.4 / source / Shell ƒ / error.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  2.9 KB  |  78 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        error.c
  4.  
  5. Purpose:    This module handles altering the user when an error has
  6.             occurred.  (If the program is currently in the background,
  7.             we use the Notification Manager to queue a notification
  8.             request and display the alert as soon as we are in the
  9.             foreground -- see main.c, DispatchEvents, case osEvt.)
  10.  
  11. This program is free software; you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation; either version 2 of the License, or
  14. (at your option) any later version.
  15.  
  16. This program is distributed in the hope that it will be useful,
  17. but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. GNU General Public License for more details.
  20.  
  21. You should have received a copy of the GNU General Public License
  22. along with this program in a file named "GNU General Public License".
  23. If not, write to the Free Software Foundation, 675 Mass Ave,
  24. Cambridge, MA 02139, USA.
  25.  
  26. \**********************************************************************/
  27.  
  28. #include "error.h"
  29. #include "main.h"
  30. #include "dialogs.h"
  31. #include "environment.h"
  32. #include "program globals.h"
  33.  
  34. NMRec            gMyNotification;
  35. int                gPendingResultCode;
  36.  
  37. void HandleError(int resultCode, Boolean exitToShell)
  38. /* if we're in the foreground, just get the error string (from the .rsrc file) and
  39.    display the error alert; otherwise, we have to queue it, put up a notification
  40.    (if possible), and wait patiently to come back in the foreground.  (see main.c,
  41.    DispatchEvents(), case osEvt. */
  42. /* All error codes are listed in program globals.h */
  43. {
  44.     Str255            tempStr;
  45.     Handle            myResHand;
  46.     
  47.     /* if there is no error, or the error is that the user cancelled an operation
  48.        in progress, don't display anything; it would only confuse them. */
  49.     if ((resultCode==userCancelErr) || (resultCode==allsWell)) return;
  50.     
  51.     if (gIsInBackground)    /* if program is in background, can't display alert immed. */
  52.     {
  53.         if (gHasNotificationManager)    /* if they don't have notification, f*ck 'em */
  54.         {
  55.             myResHand=GetResource('SICN', 1234);    /* small icon for menu bar flashing */
  56.             gMyNotification.qType=nmType;            /* for more detail on these params, */
  57.             gMyNotification.nmMark=1;                /* see IM Processes, 5-8 */
  58.             gMyNotification.nmIcon=myResHand;
  59.             gMyNotification.nmSound=(Handle)-1L;
  60.             gMyNotification.nmStr=0L;
  61.             gMyNotification.nmResp=0L;
  62.             gMyNotification.nmRefCon=0L;
  63.             NMInstall(&gMyNotification);
  64.         }
  65.         gPendingResultCode=resultCode;                /* remember error code for later */
  66.     }
  67.     else
  68.     {
  69.         GetIndString(tempStr, 129, -resultCode);    /* get error string from .rsrc */
  70.         ParamText(tempStr, "\p", "\p", "\p");
  71.         PositionDialog('ALRT', largeAlert);        /* position alert (see dialogs.c) */
  72.         StopAlert(largeAlert, 0L);                /* show it */
  73.     }
  74.     
  75.     if (exitToShell)        /* for fatal errors */
  76.         ExitToShell();
  77. }
  78.